package com.evry.spring3sandbox.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.evry.spring3sandbox.service.ProductManager;


@Controller
public class InventoryController {

	protected final Log logger = LogFactory.getLog(getClass());
	@Autowired
    private ProductManager productManager;

	@RequestMapping(value = "/")
    public String getProducts(Model model) {

    	  String now = (new java.util.Date()).toString();
          logger.info("returning hello view with " + now);

          Map<String, Object> myModel = new HashMap<String, Object>();
          myModel.put("now", now);
          myModel.put("products", this.productManager.getProducts());
          model.addAttribute("model", myModel);
          return "inventory";
    }
}
